package com.china08.yxyapi.api.manage.sch.platform.website.article;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.mg.sws.SwsArticle;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.SwsArticleRepository;

@CrossOrigin
@RestController
public class ArticleUpdAuditController {

    @Autowired
    SwsArticleRepository swsArticleRepository;

    @RequestMapping(value = "/api_yw/manage/sch/platform/website/article/upd/audit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String id = reqModel.id;
        Integer auditStatus = reqModel.auditStatus;

        Assert.isTrue(StringUtils.isNotBlank(id), "修改资讯为空");

        SwsArticle swsArticle = swsArticleRepository.findById(id);
        Assert.isTrue(null != swsArticle, "不存在当前资讯");

        swsArticle.setAuditStatus(auditStatus);
        swsArticleRepository.save(swsArticle);
        return true;
    }

    protected static class ReqModel extends YxyApiReqModel {
        public String id;
        public Integer auditStatus;
    }

    protected static class RespModel extends YxyApiRespModel {

    }
}
